package com.hq.fxh.No5_User.User.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.Modle.GetMyPostModle;
import com.hq.fxh.Modle.UserPlateModel;
import com.hq.fxh.R;
import com.hq.fxh.Utils.AppConstant;
import com.hq.fxh.Utils.GlideUtils;
import com.hq.fxh.Utils.Tool;

import java.util.List;

import static cn.jpush.android.api.JPushInterface.a.e;
import static cn.jpush.android.api.JPushInterface.a.i;
import static cn.jpush.android.api.JPushInterface.a.n;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/15
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_MyPlate extends BaseAdapter {
    List<UserPlateModel> data;
    OnDeleteCallBack onDeleteCallBack;
    String name = "Radapter_UserSpace_Plate";

    public void setOnDeleteCallBack(OnDeleteCallBack onDeleteCallBack) {
        this.onDeleteCallBack = onDeleteCallBack;
    }

    public void setData(List<UserPlateModel> data) {
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 1 : data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_myplate_plate, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if(data!=null&&data.size()>position){
            List<String> title_pic = data.get(position).getTitle_pic();
            if (title_pic == null || title_pic.size() == 0) {
                viewHolder.layoutPic.setVisibility(View.GONE);
            } else {
                viewHolder.layoutPic.setVisibility(View.VISIBLE);
                Tool.setUrlToImage(parent.getContext(), data.get(position).getTitle_pic().get(0), viewHolder.newImageView);
            }
            Tool.setStringToText(viewHolder.textTitle, data.get(position).getTitle());
            Tool.setStringToText(viewHolder.tvPlateitemName, data.get(position).getCategory_name());
            Tool.setIntToText(viewHolder.readNewNum, data.get(position).getNum_read(), name);
        }


        viewHolder.itemMyPlateDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onDeleteCallBack.deleteCall(position, data.get(position));
            }
        });

        return view;
    }

    static class ViewHolder {
        protected TextView textTitle;
        protected TextView tvPlateitemName;
        protected TextView readNewNum;
        protected TextView itemMyPlateDelete;
        protected ImageView newImageView;
        protected ImageView imageItemVideoTag;
        protected LinearLayout layoutPic;
        protected LinearLayout newsType1;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            textTitle = (TextView) rootView.findViewById(R.id.text_title);
            tvPlateitemName = (TextView) rootView.findViewById(R.id.tv_plateitem_name);
            readNewNum = (TextView) rootView.findViewById(R.id.readNewNum);
            itemMyPlateDelete = (TextView) rootView.findViewById(R.id.item_myPlate_delete);
            newImageView = (ImageView) rootView.findViewById(R.id.new_imageView);
            imageItemVideoTag = (ImageView) rootView.findViewById(R.id.image_Item_VideoTag);
            layoutPic = (LinearLayout) rootView.findViewById(R.id.layout_Pic);
            newsType1 = (LinearLayout) rootView.findViewById(R.id.newsType1);
        }
    }


    public interface OnDeleteCallBack {
        void deleteCall(int position, UserPlateModel data);
    }
}
